/*
 * Copyright 2006-2008 Michele Mostarda ( michele.mostarda@gmail.com ).
 * All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.graphnav.swing;

import org.graphnav.model.Filter;
import org.graphnav.model.GraphModel;
import org.graphnav.util.GeomUtils;

import java.awt.geom.Rectangle2D;
import java.util.Iterator;

/**
 * Provides a renderer drawing rounded corner <i>nodes</i>.
 */
public class RoundNodeLayout implements NodeLayout {

    public Filter processLayout(GraphModel model, EffectProcessor fp, int detailLevel, Node root /*, Set visited*/) {

        Node current;
        int counter = 0;
        Rectangle2D nBounds = root.getBounds2D(detailLevel);
        int totalNodes = model.outgoingNodesCount(root) + model.ingoingNodesCount(root);
        for( Iterator outgoing = model.getOutgoingNodes(root); outgoing.hasNext(); ) {
            current = (Node) outgoing.next();
            fp.addMovement(
                    current,
                    GeomUtils.getRoundPosition((int) nBounds.getX(), (int) nBounds.getY(), totalNodes, counter++)
            );

        }
        for( Iterator ingoing = model.getIngoingNodes(root); ingoing.hasNext(); ) {
            current = (Node) ingoing.next();
            fp.addMovement(
                    current,
                    GeomUtils.getRoundPosition((int) nBounds.getX(), (int) nBounds.getY(), totalNodes, counter++)
            );

        }

        return null;

    }
}
